package com.livegoods.rabbitmq.dao.impl;

import com.livegoods.pojo.House;
import com.livegoods.rabbitmq.dao.HouseDao4MongoDB;
import com.mongodb.client.result.UpdateResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;


@Repository
public class HouseDao4MongoDBImpl implements HouseDao4MongoDB {


    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public long updateRented(String houseId) {



        Query query = new Query(Criteria.where("id").is(houseId));

        Update rented = Update.update("rented", true);

        UpdateResult updateResult = mongoTemplate.updateFirst(query, rented, House.class);

        long row = updateResult.getModifiedCount();

        return row;
    }
}
